package com.rabbitmq.demo.conf;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 路由模式
 *
 * @Author yi.cheng
 * @Date 2023-7-13 09:14
 **/
@Configuration
public class RoutingQueueConfig {
    // 定义队列1，2
    public final static String ROUTING_QUEUE_ONE = "routing_queue_one";
    public final static String ROUTING_QUEUE_TWO = "routing_queue_two";
    // 定义交换机名
    public final static String ROUTING_DIRECT_EXCHANGE = "routing_direct_exchange";

    // direct 路由模式队列
    @Bean
    public Queue directQueueOne() {
        return new Queue(ROUTING_QUEUE_ONE, true);
    }

    @Bean
    public Queue directQueueTwo() {
        return new Queue(ROUTING_QUEUE_TWO, true);
    }

    // direct 交换机
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(ROUTING_DIRECT_EXCHANGE);
    }

    // 路由模式绑定队列到交换机
    @Bean
    public Binding directExchangeBingingOne() {
        return BindingBuilder.bind(directQueueOne()).to(directExchange()).with("orange");
    }

    @Bean
    public Binding directExchangeBingingTwo() {
        return BindingBuilder.bind(directQueueTwo()).to(directExchange()).with("black");
    }
}
